/**
 *
 */
import Util;
import GatewayClient;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @productId = 'NonStandardOpen';
  var gatewayClient = new GatewayClient();
  @spi = gatewayClient;
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nonstandardopen', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetTokenRequest {
  appKey?: string(name='appKey', example='***'),
  appSecret?: string(name='appSecret', example='***'),
}

model GetTokenResponseBody = {
  data?: {
    expireTime?: string(name='expireTime', example='7200'),
    generateTime?: string(name='generateTime', example='1724130275'),
    token?: string(name='token', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  }(name='data'),
  errorCode?: string(name='errorCode', example='system_error'),
  errorMsg?: string(name='errorMsg'),
  requestId?: string(name='requestId', description='Id of the request', example='C928528C-8934-5EAF-BDFD-C3F6C272ABF1'),
  status?: int32(name='status', example='200'),
  success?: string(name='success', example='true'),
}

model GetTokenResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTokenResponseBody(name='body'),
}

/**
 * @summary 创建分销token
 *
 * @param request GetTokenRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTokenResponse
 */
async function getTokenWithOptions(request: GetTokenRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetTokenResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    query['appKey'] = request.appKey;
  }
  if (!Util.isUnset(request.appSecret)) {
    query['appSecret'] = request.appSecret;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetToken',
    version = '2024-09-22',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/nonstandard/getToken`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 创建分销token
 *
 * @param request GetTokenRequest
 * @return GetTokenResponse
 */
async function getToken(request: GetTokenRequest): GetTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getTokenWithOptions(request, headers, runtime);
}

model InitCardHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US'),
}

model InitCardRequest {
  bizParam?: string(name='bizParam', example='{
    "itemId": 123456,
    "skuId": 123456789,
    "mobile": 13111111111,
    "buyAmount": 1,
    "outOrderId": "123456789"
}'),
}

model InitCardResponseBody = {
  data?: string(name='data', example='{
    "orderId": 123456
}'),
  errorCode?: string(name='errorCode', example='system_error'),
  errorMsg?: string(name='errorMsg'),
  status?: int32(name='status', example='200'),
  success?: boolean(name='success', example='true'),
}

model InitCardResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: InitCardResponseBody(name='body'),
}

/**
 * @summary 分销生卡
 *
 * @param request InitCardRequest
 * @param headers InitCardHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return InitCardResponse
 */
async function initCardWithOptions(request: InitCardRequest, headers: InitCardHeaders, runtime: Util.RuntimeOptions): InitCardResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bizParam)) {
    query['bizParam'] = request.bizParam;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'InitCard',
    version = '2024-09-22',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/nonstandard/initCard`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 分销生卡
 *
 * @param request InitCardRequest
 * @return InitCardResponse
 */
async function initCard(request: InitCardRequest): InitCardResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new InitCardHeaders{};
  return initCardWithOptions(request, headers, runtime);
}

model QueryOrderInfoHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US'),
}

model QueryOrderInfoRequest {
  bizParam?: string(name='bizParam', example='{
    "itemId": 123456,
    "skuId": 123456789,
    "mobile": 13111111111,
    "buyAmount": 1,
    "outOrderId": "123456789"
}'),
}

model QueryOrderInfoResponseBody = {
  data?: string(name='data', example='{
    "orderId": 123456
}'),
  errorCode?: string(name='errorCode', example='system_error'),
  errorMsg?: string(name='errorMsg'),
  status?: int32(name='status', example='200'),
  success?: boolean(name='success', example='true'),
}

model QueryOrderInfoResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryOrderInfoResponseBody(name='body'),
}

/**
 * @summary 分销订单信息查询
 *
 * @param request QueryOrderInfoRequest
 * @param headers QueryOrderInfoHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return QueryOrderInfoResponse
 */
async function queryOrderInfoWithOptions(request: QueryOrderInfoRequest, headers: QueryOrderInfoHeaders, runtime: Util.RuntimeOptions): QueryOrderInfoResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bizParam)) {
    query['bizParam'] = request.bizParam;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryOrderInfo',
    version = '2024-09-22',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/nonstandard/queryOrderInfo`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 分销订单信息查询
 *
 * @param request QueryOrderInfoRequest
 * @return QueryOrderInfoResponse
 */
async function queryOrderInfo(request: QueryOrderInfoRequest): QueryOrderInfoResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new QueryOrderInfoHeaders{};
  return queryOrderInfoWithOptions(request, headers, runtime);
}

model RefundConfirmHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US'),
}

model RefundConfirmRequest {
  bizParam?: string(name='bizParam', example='{
    "itemId": 123456,
    "skuId": 123456789,
    "mobile": 13111111111,
    "buyAmount": 1,
    "outOrderId": "123456789"
}'),
}

model RefundConfirmResponseBody = {
  data?: string(name='data', example='null'),
  errorCode?: string(name='errorCode', example='system_error'),
  errorMsg?: string(name='errorMsg'),
  status?: int32(name='status', example='200'),
  success?: boolean(name='success', example='true'),
}

model RefundConfirmResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RefundConfirmResponseBody(name='body'),
}

/**
 * @summary 分销退确认
 *
 * @param request RefundConfirmRequest
 * @param headers RefundConfirmHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return RefundConfirmResponse
 */
async function refundConfirmWithOptions(request: RefundConfirmRequest, headers: RefundConfirmHeaders, runtime: Util.RuntimeOptions): RefundConfirmResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bizParam)) {
    query['bizParam'] = request.bizParam;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RefundConfirm',
    version = '2024-09-22',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/nonstandard/refundConfirm`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 分销退确认
 *
 * @param request RefundConfirmRequest
 * @return RefundConfirmResponse
 */
async function refundConfirm(request: RefundConfirmRequest): RefundConfirmResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new RefundConfirmHeaders{};
  return refundConfirmWithOptions(request, headers, runtime);
}

model RefundSubmitHeaders {
  commonHeaders?: map[string]string,
  xAcsAirticketAccessToken?: string(name='xAcsAirticketAccessToken', description='token', example='eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpc3RyaWJ1dGlvbl9rZXlpZCJ9.eyJqdGkiOiI2cDQwZDctSDQ0dUJicEJkYTZadzdBIiwiaWF0IjoxNzI0MzE2MzM1LCJleHAiOjE3MjQzMjM1MzUsIm5iZiI6MTcyNDMxNjI3NSwiYXBwS2V5IjoiNjE3NzgxZDQxM2FmNGRlZGFiNzkifQ.XtjSM7qVbESvt7n31RtD5Pp6854IVyGMEco4aEruMDMkrXHkcdZejyecKFx3RdsCldZPgvowc5EOl44c3JJfm6DENH4M6BRBSc90eqXYcD_xVJ9FhDWzK9O6OnkvR7HX1t-qqMdikLviM1w1G0DGMLaasvZ8MPMewL8k6NnvOSGePwUhb-m5IZ14VYv7BPO2dp8Jh00qNSJQrmNiWWzJUtK_xllNr3LKQ7cIVtPgFUckvRDw9Hal5oACXSRdkZFOAGlFSjpB_BbTpe5vc-AJ8K89nRD53sIy9YyVQClV_HH7PrXxFFJgReGvNsnP1h9gf55q86IzOQBkj9vGm2zXdw'),
  xAcsAirticketLanguage?: string(name='xAcsAirticketLanguage', example='en_US'),
}

model RefundSubmitRequest {
  bizParam?: string(name='bizParam', example='{
    "itemId": 123456,
    "skuId": 123456789,
    "mobile": 13111111111,
    "buyAmount": 1,
    "outOrderId": "123456789"
}'),
}

model RefundSubmitResponseBody = {
  data?: string(name='data', example='{
    "orderId": 123456
}'),
  errorCode?: string(name='errorCode', example='system_error'),
  errorMsg?: string(name='errorMsg'),
  status?: int32(name='status', example='200'),
  success?: boolean(name='success', example='true'),
}

model RefundSubmitResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RefundSubmitResponseBody(name='body'),
}

/**
 * @summary 分销退提交
 *
 * @param request RefundSubmitRequest
 * @param headers RefundSubmitHeaders
 * @param runtime runtime options for this request RuntimeOptions
 * @return RefundSubmitResponse
 */
async function refundSubmitWithOptions(request: RefundSubmitRequest, headers: RefundSubmitHeaders, runtime: Util.RuntimeOptions): RefundSubmitResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bizParam)) {
    query['bizParam'] = request.bizParam;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAirticketAccessToken)) {
    realHeaders['xAcsAirticketAccessToken'] = Util.toJSONString(headers.xAcsAirticketAccessToken);
  }
  if (!Util.isUnset(headers.xAcsAirticketLanguage)) {
    realHeaders['xAcsAirticketLanguage'] = Util.toJSONString(headers.xAcsAirticketLanguage);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'RefundSubmit',
    version = '2024-09-22',
    protocol = 'HTTPS',
    pathname = `/v1/distribution/nonstandard/refundSubmit`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 分销退提交
 *
 * @param request RefundSubmitRequest
 * @return RefundSubmitResponse
 */
async function refundSubmit(request: RefundSubmitRequest): RefundSubmitResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new RefundSubmitHeaders{};
  return refundSubmitWithOptions(request, headers, runtime);
}

